package com.kerpow.KSheet.character;

import android.database.Cursor;

public class Power {
	public String ID;
	public String Name;
	public String Usage;
	public String ActionType;
	public String AttackBonus;
	public String Damage;
	public String Defense;
	public String WebDetail;
	public String WebURL;
	public boolean Used;
	
	public Power(){
		Name = "";
		Usage = "";
		ActionType = "";
		AttackBonus = "";
		Defense = "";
		Damage = "";
		WebURL = "";
		WebDetail = "";
		Used = false;
	}
	
	public static Power from(Cursor c){
		Power p = new Power();
		p.ID = c.getString(c.getColumnIndex(CharacterAdapter.FIELD_POWERS_ID));
		p.Name = c.getString(c.getColumnIndex(CharacterAdapter.FIELD_POWERS_NAME));
		p.Usage = c.getString(c.getColumnIndex(CharacterAdapter.FIELD_POWERS_USAGE));
		p.ActionType = c.getString(c.getColumnIndex(CharacterAdapter.FIELD_POWERS_ACTION));
		p.AttackBonus = c.getString(c.getColumnIndex(CharacterAdapter.FIELD_POWERS_ATTACKBONUS));
		p.Defense = c.getString(c.getColumnIndex(CharacterAdapter.FIELD_POWERS_DEFENSE));
		p.Damage = c.getString(c.getColumnIndex(CharacterAdapter.FIELD_POWERS_DAMAGE));
		p.WebURL = c.getString(c.getColumnIndex(CharacterAdapter.FIELD_POWERS_WEBURL));
		p.WebDetail = c.getString(c.getColumnIndex(CharacterAdapter.FIELD_POWERS_WEBDETAIL));
		p.Used = c.getInt(c.getColumnIndex(CharacterAdapter.FIELD_POWERS_USED)) == 1;
		
		return p;
	}
	
	public String getSmallDetail(){
		String ret="";
		if(!AttackBonus.equals(""))
			ret += "+" + AttackBonus + " vs " + Defense;
		
		if(!Damage.equals("")) 
			ret += " " + Damage + " damage";

		if(ret.length() > 0) 
			return "Roll: " + ret;
		else
			return "";
	}
	
	public String getDetail(){
		String ret="";
		ret += Usage;
		ret += "\n";
		ret += ActionType;
		ret += "\n";
		if(!AttackBonus.equals(""))
			ret += "+" + AttackBonus + " vs " + Defense;
		if(!Damage.equals("")) 
			ret += "\n" + Damage;
				
		return ret;
	}
}
